package org.hcyspartnoc.luoxin.pojo.vo.searchtopic;


import lombok.Data;
import lombok.NoArgsConstructor;
import org.hcyspartnoc.luoxin.pojo.dto.searchtopic.TopicRagDto;
import org.hcyspartnoc.luoxin.pojo.po.searchtopic.QuestionOptionPo;
import org.hcyspartnoc.luoxin.pojo.po.searchtopic.QuestionPo;

import java.io.Serial;
import java.util.ArrayList;
import java.util.List;

@Data
@NoArgsConstructor
public class QuestionVo {

    private Integer id;
    private Integer bankId;
    private String queTopic;
    private String queAnswer;
    private String queAnalysis;
    private Long queType;
    private String aiAnalysis;
    private List<QuestionOptions> options = new ArrayList<>();  // 初始化选项列表



    @Data
    @NoArgsConstructor
    public static class QuestionOptions {  // 改为静态类以便外部访问
        private Integer queId;
        private String option;
        private Integer id;

        // 构造函数用于直接创建选项
        public QuestionOptions(String option) {
            this.option = option;
        }
        public QuestionOptions(Integer queId) {
            this.queId = queId;
        }

        public QuestionOptions(Integer questionId, String option) {
            this.queId = questionId;
            this.option = option;
        }
    }

    // 方法用于添加选项
    public void addOption(String option) {
        this.options.add(new QuestionOptions(option));
    }
    // 设置所有选项的 queId，作为关联问题的主键
    public void setOptionsQueId(Integer queId) {
        for (QuestionOptions option : this.options) {
            option.setQueId(queId);  // 为每个选项设置问题主键ID
        }
    }
    // 根据 List<QuestionOptionPo> 设置 options 列表
    public void setOptionsFromPo(List<QuestionOptionPo> questionOptionPos) {
        for (QuestionOptionPo questionOptionPo : questionOptionPos) {
            QuestionOptions option = new QuestionOptions(
                    questionOptionPo.getQuestionId(),
                    questionOptionPo.getOption()
            );
            this.options.add(option);
        }
    }
    public void addOptionByRag(TopicRagDto topicRagDto) {
        for (TopicRagDto.QuestionOptions questionOptions : topicRagDto.getOptions()) {
            QuestionOptions option = new QuestionOptions(
                    questionOptions.getOption()
            );
            this.options.add(option);
        }
    }
}
